/****************************************************************************
* Copyright (c) 2008, j. montgomery, ATGi                                   *
* All rights reserved.                                                      *
*                                                                           *
* Redistribution and use in source and binary forms, with or without        *
* modification, are permitted provided that the following conditions        *
* are met:                                                                  *
*                                                                           *
* - Redistributions of source code must retain the above copyright          *
*   notice, this list of conditions and the following disclaimer.           *
*                                                                           *
* - Redistributions in binary form must reproduce the above                 *
*   copyright notice, this list of conditions and the following             *
*   disclaimer in the documentation and/or other materials provided         *
*   with the distribution.                                                  *
*                                                                           *
* - Neither the name of ATGi nor the names of its contributors may          *
*   be used to endorse or promote products derived from this software       *
*   without specific prior written permission.                              *
*                                                                           *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS       *
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT         *
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS         *
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE            *
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,       *
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES                  *
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR        *
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)        *
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,       *
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)             *
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED       *
* OF THE POSSIBILITY OF SUCH DAMAGE.                                        *
*****************************************************************************
*/
using System;
using System.Collections.Generic;
using DnSmtp.Message;

namespace DnSmtp
{

    public class FailedRecipient
    {
        private EmailAddress _failedAddress;

        public EmailAddress FailedAddress
        {
          get { return _failedAddress; }
          set { _failedAddress = value; }
        }

        private Exception _exception;

        public Exception Exception
        {
          get { return _exception; }
          set { _exception = value; }
        }

        public FailedRecipient(Exception exception, EmailAddress failedAddress) 
        {
            _exception = exception;
            _failedAddress = failedAddress;
        }
    }
	/// <summary>
	/// The exception that is thrown when a when a 'RCPT TO:emai@addr.com' is sent to the 
	/// server and is rejected for any reason.
	/// </summary>
	public class RecipientFailedException : ApplicationException 
	{
        private List<FailedRecipient> _failedRecipients;

		//private EmailAddressList _failedRecipientList = new EmailAddressList();
		
		/// <summary>
		/// Initializes a new instance of the RecipientFailedException class with default properties.
		/// </summary>
		public RecipientFailedException()
			:base() 
		{
            _failedRecipients = new List<FailedRecipient>();
		}
		
		/// <summary>
		/// Initializes a new instance of the RecipientFailedException class with a specified error message.
		/// </summary>
		/// <param name="message">The error message that explains the reason for the exception.</param>
		public RecipientFailedException(string message) 
			: base(message) 
		{
            _failedRecipients = new List<FailedRecipient>();
		}
		
		/// <summary>
		/// Initializes a new instance of the RecipientFailedException class with a specified error message and a reference to the innerException that is the root cause of this Exception.
		/// </summary>
		/// <param name="message">The error message that explains the reason for the exception.</param>
		/// <param name="innerException">An instance of an Exception that is the cause of the current Exception. If innerException is non-null the the current Exception is raised in a catch block handling innerException.</param>
		public RecipientFailedException(string message, Exception innerException) 
			: base(message, innerException) 
		{
            _failedRecipients = new List<FailedRecipient>();
		}

        internal void AddFailedRecipient(FailedRecipient recipient)
        {
            _failedRecipients.Add(recipient);   
        }
		
		internal void AddFailedRecipients(List<FailedRecipient> failedRecipients) 
		{
            _failedRecipients.AddRange(failedRecipients);
		}

        public List<FailedRecipient> FailedRecipients
        {
            get { return _failedRecipients; }
        }
		/// <summary>
		/// An arrayList of the failed recipient email addresses.
		/// </summary>
		/// <returns>An ArrayList that contains all of the failed Recipients.</returns>
        //public EmailAddressList FailedRecipientList
        //{
        //    get
        //    {
        //        return _failedRecipientList.Clone();
        //    }
        //}
	}

	/// <summary>
	/// The Exception that is thrown when the SMTP server returns an error code for any reason.
	/// </summary>
	public class SmtpCommunicationException : ApplicationException 
	{
		public string SmtpErrorLog;
		/// <summary>
		/// Initializes a new instance of the RecipientFailedException class with default properties.
		/// </summary>
		public SmtpCommunicationException() 
			: base() 
		{
		}

		/// <summary>
		/// Initializes a new instance of the SmtpCommunicationException class with a specified error message.
		/// </summary>
		/// <param name="Message">The error message that explains the reason for the exception.</param>
		public SmtpCommunicationException(string Message) 
			: base(Message) 
		{
		}
		
		/// <summary>
		/// Initializes a new instance of the SmtpCommunicationException class with a specified error message and a reference to the innerException that is the root cause of this Exception.
		/// </summary>
		/// <param name="message">The error message that explains the reason for the exception.</param>
		/// <param name="innerException">An instance of an Exception that is the cause of the current Exception. If innerException is non-null the the current Exception is raised in a catch block handling innerException.</param>
		public SmtpCommunicationException(string message, Exception innerException) 
			: base(message, innerException) 
		{
		}

		public SmtpCommunicationException(string message, string sSmtpErrorLog) :
			base(message) 
		{
			SmtpErrorLog = sSmtpErrorLog;
		}
	}
}
